package com.gm.census.service.impl;

import com.gm.census.model.pojo.Entry;
import com.gm.census.model.pojo.SearchEntry;
import com.gm.census.service.IndexService;
import com.gm.census.service.UserInfoFacade;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

public class IndexServiceImpl implements IndexService {

	private static Objectify begin() {
		return ObjectifyService.begin();
	}

	private UserInfoFacade userInfo;

	@Override
	public Boolean index(String id, String ns, String text) {

		return false;

	}

	protected String empty(String val) {
		if (val != null && val.length() > 0)
			return val;
		else
			return "";
	}

	@Override
	public Boolean index(String id, String ns, Entry e) {
		StringBuilder text = new StringBuilder();
		if (id == null || id.length() <= 0)
			return false;

		text.append(empty(e.getName())).append(",")
				.append(empty(e.getStreet())).append(",")
				.append(empty(e.getDistrict())).append(",")
				.append(empty(e.getCity())).append(",")
				.append(empty(e.getCountry())).append(",")
				.append(empty(e.getHomephone())).append(",")
				.append(empty(e.getWorkphone())).append(",")
				.append(empty(e.getCellphone()));

		return index(id, ns, text.toString());
	}

	public UserInfoFacade getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfoFacade userInfo) {
		this.userInfo = userInfo;
	}

}
